package gold.digger;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC215 {
    public long startExecuteTime = System.currentTimeMillis();

    //    Input: [3,2,3,1,2,4,5,5,6] and k = 4
//    Output: 4
    public int findKthLargest(int[] arr, int k) {
        PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>(k, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });

        for (int i = 0; i < arr.length; i++) {
            maxHeap.offer(arr[i]);
            if (maxHeap.size() > k) {
                maxHeap.poll();
            }
        }

        return maxHeap.peek();
    }

    public static int getDivision(int n) {
        try {
            n += 1;
            if (n / 0 > 0) {
                n += 10;
            } else {
                n -= 10;
            }
            return n;
        } catch (Exception e) {
            n++;
        }
        n++;
        return n++;
    }

    public static void main(String[] args) {
        LC215 an = new LC215();
        int[] arr = {3, 2, 3, 1, 2, 4, 5, 5, 6};
//        System.out.println(an.findKthLargest(arr, 4));
        System.out.println(getDivision(1));
        System.out.println("\nanswer total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
